package io.gitee.twoke.generator.engine.impl.persistence.entity;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class TemplateFileEntityImpl extends AbstractEntity implements TemplateFileEntity {

    private String templateId;
    private String filenameExpression;
    private byte[] content;
    private String name;
    private String templateName;

    @Override
    public void setFilenameExpression(String filenameExpression) {
        this.filenameExpression = filenameExpression;
    }

    @Override
    public void setTemplateId(String templateId) {
        this.templateId = templateId;
    }

    @Override
    public void setContent(String content) {
        this.content = content.getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }

    @Override
    public Object getPersistentState() {
        Map<String, Object> data = new HashMap<>();
        data.put("id", id);
        data.put("templateId", templateId);
        data.put("filenameExpression", filenameExpression);
        data.put("content", getContent());
        data.put("name", name);
        return data;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getTemplateId() {
        return templateId;
    }

    @Override
    public String getFilenameExpression() {
        return filenameExpression;
    }

    @Override
    public String getContent() {
        return new String(content, StandardCharsets.UTF_8);
    }

    @Override
    public String getTemplateName() {
        return templateName;
    }

}
